Partial Public Class DTSDeploy
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents txtPassword As System.Windows.Forms.TextBox
    Friend WithEvents txtUserName As System.Windows.Forms.TextBox
    Friend WithEvents txtSrvName As System.Windows.Forms.TextBox
    Friend WithEvents lblPassword As System.Windows.Forms.Label
    Friend WithEvents lblUserName As System.Windows.Forms.Label
    Friend WithEvents lblSrvName As System.Windows.Forms.Label
    Friend WithEvents lbMessage As System.Windows.Forms.ListBox
    Friend WithEvents btnDeploy As System.Windows.Forms.Button
    Friend WithEvents txtPkgListFileNameWPath As System.Windows.Forms.TextBox
    Friend WithEvents btnFileOpenDialog As System.Windows.Forms.Button
    Friend WithEvents btnTestConn As System.Windows.Forms.Button
    Friend WithEvents btnExit As System.Windows.Forms.Button
    Friend WithEvents lbManifestFileNameWPath As System.Windows.Forms.Label
    Friend WithEvents chkTrusted As System.Windows.Forms.CheckBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(DTSDeploy))
        Me.txtPassword = New System.Windows.Forms.TextBox
        Me.txtUserName = New System.Windows.Forms.TextBox
        Me.txtSrvName = New System.Windows.Forms.TextBox
        Me.lblPassword = New System.Windows.Forms.Label
        Me.lblUserName = New System.Windows.Forms.Label
        Me.lblSrvName = New System.Windows.Forms.Label
        Me.lbMessage = New System.Windows.Forms.ListBox
        Me.btnDeploy = New System.Windows.Forms.Button
        Me.txtPkgListFileNameWPath = New System.Windows.Forms.TextBox
        Me.lbManifestFileNameWPath = New System.Windows.Forms.Label
        Me.btnFileOpenDialog = New System.Windows.Forms.Button
        Me.btnTestConn = New System.Windows.Forms.Button
        Me.btnExit = New System.Windows.Forms.Button
        Me.chkTrusted = New System.Windows.Forms.CheckBox
        Me.SuspendLayout()
        '
        'txtPassword
        '
        Me.txtPassword.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.txtPassword.Location = New System.Drawing.Point(344, 28)
        Me.txtPassword.Name = "txtPassword"
        Me.txtPassword.PasswordChar = Global.Microsoft.VisualBasic.ChrW(42)
        Me.txtPassword.Size = New System.Drawing.Size(160, 20)
        Me.txtPassword.TabIndex = 28
        '
        'txtUserName
        '
        Me.txtUserName.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.txtUserName.Location = New System.Drawing.Point(92, 28)
        Me.txtUserName.Name = "txtUserName"
        Me.txtUserName.Size = New System.Drawing.Size(160, 20)
        Me.txtUserName.TabIndex = 27
        '
        'txtSrvName
        '
        Me.txtSrvName.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.txtSrvName.Location = New System.Drawing.Point(92, 4)
        Me.txtSrvName.Name = "txtSrvName"
        Me.txtSrvName.Size = New System.Drawing.Size(160, 20)
        Me.txtSrvName.TabIndex = 25
        Me.txtSrvName.Text = "(local)"
        '
        'lblPassword
        '
        Me.lblPassword.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.lblPassword.Location = New System.Drawing.Point(256, 32)
        Me.lblPassword.Name = "lblPassword"
        Me.lblPassword.Size = New System.Drawing.Size(84, 16)
        Me.lblPassword.TabIndex = 29
        Me.lblPassword.Text = "Password:"
        '
        'lblUserName
        '
        Me.lblUserName.Location = New System.Drawing.Point(4, 32)
        Me.lblUserName.Name = "lblUserName"
        Me.lblUserName.Size = New System.Drawing.Size(84, 16)
        Me.lblUserName.TabIndex = 26
        Me.lblUserName.Text = "User Name:"
        '
        'lblSrvName
        '
        Me.lblSrvName.Location = New System.Drawing.Point(4, 8)
        Me.lblSrvName.Name = "lblSrvName"
        Me.lblSrvName.Size = New System.Drawing.Size(84, 16)
        Me.lblSrvName.TabIndex = 24
        Me.lblSrvName.Text = "Server Name:"
        '
        'lbMessage
        '
        Me.lbMessage.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.lbMessage.Location = New System.Drawing.Point(4, 76)
        Me.lbMessage.Name = "lbMessage"
        Me.lbMessage.Size = New System.Drawing.Size(500, 368)
        Me.lbMessage.TabIndex = 30
        '
        'btnDeploy
        '
        Me.btnDeploy.Anchor = CType(((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.btnDeploy.Enabled = False
        Me.btnDeploy.Font = New System.Drawing.Font("Microsoft Sans Serif", 15.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.btnDeploy.Location = New System.Drawing.Point(256, 448)
        Me.btnDeploy.Name = "btnDeploy"
        Me.btnDeploy.Size = New System.Drawing.Size(248, 68)
        Me.btnDeploy.TabIndex = 31
        Me.btnDeploy.Text = "Deploy"
        '
        'txtPkgListFileNameWPath
        '
        Me.txtPkgListFileNameWPath.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.txtPkgListFileNameWPath.Location = New System.Drawing.Point(92, 52)
        Me.txtPkgListFileNameWPath.Name = "txtPkgListFileNameWPath"
        Me.txtPkgListFileNameWPath.Size = New System.Drawing.Size(372, 20)
        Me.txtPkgListFileNameWPath.TabIndex = 32
        '
        'lbManifestFileNameWPath
        '
        Me.lbManifestFileNameWPath.Location = New System.Drawing.Point(4, 56)
        Me.lbManifestFileNameWPath.Name = "lbManifestFileNameWPath"
        Me.lbManifestFileNameWPath.Size = New System.Drawing.Size(84, 16)
        Me.lbManifestFileNameWPath.TabIndex = 33
        Me.lbManifestFileNameWPath.Text = "Manifest File:"
        '
        'btnFileOpenDialog
        '
        Me.btnFileOpenDialog.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.btnFileOpenDialog.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.btnFileOpenDialog.Location = New System.Drawing.Point(468, 52)
        Me.btnFileOpenDialog.Name = "btnFileOpenDialog"
        Me.btnFileOpenDialog.Size = New System.Drawing.Size(36, 20)
        Me.btnFileOpenDialog.TabIndex = 34
        Me.btnFileOpenDialog.Text = "..."
        '
        'btnTestConn
        '
        Me.btnTestConn.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.btnTestConn.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.btnTestConn.Location = New System.Drawing.Point(128, 448)
        Me.btnTestConn.Name = "btnTestConn"
        Me.btnTestConn.Size = New System.Drawing.Size(125, 68)
        Me.btnTestConn.TabIndex = 35
        Me.btnTestConn.Text = "Test Connection"
        '
        'btnExit
        '
        Me.btnExit.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
        Me.btnExit.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.btnExit.Location = New System.Drawing.Point(4, 448)
        Me.btnExit.Name = "btnExit"
        Me.btnExit.Size = New System.Drawing.Size(120, 68)
        Me.btnExit.TabIndex = 36
        Me.btnExit.Text = "Exit"
        '
        'chkTrusted
        '
        Me.chkTrusted.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.chkTrusted.Checked = True
        Me.chkTrusted.CheckState = System.Windows.Forms.CheckState.Checked
        Me.chkTrusted.Location = New System.Drawing.Point(256, 8)
        Me.chkTrusted.Name = "chkTrusted"
        Me.chkTrusted.Size = New System.Drawing.Size(108, 16)
        Me.chkTrusted.TabIndex = 37
        Me.chkTrusted.Text = "Trusted Connection"
        '
        'DTSDeploy
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(508, 518)
        Me.Controls.Add(Me.chkTrusted)
        Me.Controls.Add(Me.btnExit)
        Me.Controls.Add(Me.btnTestConn)
        Me.Controls.Add(Me.btnFileOpenDialog)
        Me.Controls.Add(Me.lbManifestFileNameWPath)
        Me.Controls.Add(Me.txtPkgListFileNameWPath)
        Me.Controls.Add(Me.btnDeploy)
        Me.Controls.Add(Me.lbMessage)
        Me.Controls.Add(Me.txtPassword)
        Me.Controls.Add(Me.txtUserName)
        Me.Controls.Add(Me.txtSrvName)
        Me.Controls.Add(Me.lblPassword)
        Me.Controls.Add(Me.lblUserName)
        Me.Controls.Add(Me.lblSrvName)
        Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
        Me.MinimumSize = New System.Drawing.Size(524, 350)
        Me.Name = "DTSDeploy"
        Me.Text = "Deploy DTS Jobs"
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub

#End Region

#Region "GUI Generated Events"
    Private Sub btnFileOpenDialog_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFileOpenDialog.Click
        Try
            Dim _oOpenFileDialog As New OpenFileDialog
            Dim _sJobFilePath As String = ""
            Dim _sJobFileName As String = ""

            _oOpenFileDialog.Filter = "XML Config Files (*.xml)|*.xml"
            _oOpenFileDialog.FilterIndex = 1
            _oOpenFileDialog.Multiselect = False

            _oOpenFileDialog.ShowDialog()

            If _oOpenFileDialog.FileName.Length > 0 Then
                __sPkgListFileName = _oOpenFileDialog.FileName.Substring(_oOpenFileDialog.FileName.LastIndexOf("\") + 1, _oOpenFileDialog.FileName.Length - _oOpenFileDialog.FileName.LastIndexOf("\") - 1)
                __sPkgListFilePath = _oOpenFileDialog.FileName.Substring(0, _oOpenFileDialog.FileName.LastIndexOf(__sPkgListFileName))

                txtPkgListFileNameWPath.Text = __sPkgListFilePath & __sPkgListFileName
                btnDeploy.Enabled = True
            Else
                txtPkgListFileNameWPath.Text = ""
                btnDeploy.Enabled = False
            End If
        Catch ex As Exception
            MsgBox("Exception Raised in btnFileOpenDialog_Click: " & ex.ToString, MsgBoxStyle.OkOnly, "Exception Raised")
        End Try
    End Sub

    Private Sub btnTestConn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTestConn.Click
        Try
            Dim _sSrvName As String

            btnTestConn.Enabled = False

            InitDeploy()

            _sSrvName = TestConnection()

            If _sSrvName Is Nothing Then
                lbMessage.Items.Add("Test of Database connection failed, aborting deployment.")
                lbMessage.Items.Add("Message returned: " & __sMessage)
                __sMessage = ""
            Else
                lbMessage.Items.Add("Connected to server: " & _sSrvName)
                __sMessage = ""
            End If

            btnTestConn.Enabled = True
        Catch ex As Exception
            MsgBox("Exception Raised in btnTestConn_Click: " & ex.ToString, MsgBoxStyle.OkOnly, "Exception Raised")
            btnTestConn.Enabled = True
        End Try
    End Sub

    Private Sub btnDeploy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDeploy.Click
        Try
            Dim _sSrvName As String
            Dim _fOk As Boolean

            _fOk = FileExistChk(__sPkgListFilePath, __sPkgListFileName)

            If _fOk = False Then
                lbMessage.Items.Add("DTS Package Manifest File does not exist at location specified.")
                lbMessage.Items.Add("Aborting deployment.")
                Return
            Else
                lbMessage.Items.Add("DTS Package Manifest File exists.")
            End If

            InitDeploy()

            _sSrvName = TestConnection()

            If _sSrvName Is Nothing Then
                lbMessage.Items.Add("Test of Database connection failed, aborting deployment.")
                lbMessage.Items.Add("Message returned: " & __sMessage)
                __sMessage = ""
                Return
            Else
                lbMessage.Items.Add("Connected to server: " & _sSrvName)
                __sMessage = ""
            End If

            btnDeploy.Enabled = False

            GetDeployList(__sPkgListFilePath, __sPkgListFileName)

            DeployList()

            btnDeploy.Enabled = True
        Catch ex As Exception
            MsgBox("Exception Raised in btnDeploy_Click: " & ex.ToString, MsgBoxStyle.OkOnly, "Exception Raised")
        End Try
    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        End
    End Sub

    Private Sub txtPkgListFileNameWPath_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtPkgListFileNameWPath.TextChanged
        If txtPkgListFileNameWPath.Text.Length = 0 Then
            btnDeploy.Enabled = False
        Else
            btnDeploy.Enabled = True
        End If
    End Sub

    Private Sub chkTrusted_CheckStateChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkTrusted.CheckStateChanged
        If chkTrusted.CheckState = CheckState.Checked Then
            txtUserName.Enabled = False
            txtPassword.Enabled = False
        ElseIf chkTrusted.CheckState = CheckState.Unchecked Then
            txtUserName.Enabled = True
            txtPassword.Enabled = True
        ElseIf chkTrusted.CheckState = CheckState.Indeterminate Then
            chkTrusted.CheckState = CheckState.Unchecked
        End If
    End Sub
#End Region

End Class
